package com.liang.practice.server.rpc;

import com.liang.auth.api.api.UserFeignService;
import com.liang.auth.api.entity.AuthUserDTO;
import com.liang.auth.api.entity.Result;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class UserRpc {

    @Resource
    private UserFeignService userFeignService;

    public UserInfo getUserInfo(String username) {
        AuthUserDTO authUserDTO = new AuthUserDTO();
        authUserDTO.setUsername(username);
        Result<AuthUserDTO> result = userFeignService.getUserInfo(authUserDTO);
        UserInfo userInfo = new UserInfo();
        if (!result.isSuccess()) {
            return userInfo;
        }
        AuthUserDTO data = result.getData();
        userInfo.setUsername(data.getUsername());
        userInfo.setNickname(data.getNickname());
        userInfo.setAvatar(data.getAvatar());
        return userInfo;
    }

}